<template>
	<div id="app">
        <div class="container">
            <input-box
                class="textarea"
                placeholder="请输入内容"
                ref="inputBox"
                defaultText="默认内容测试"
                :pasteImg="true"
                @change="change"
                @pasteFileChange="pasteFileChange">
            </input-box>
        </div>
        <div class="mock">
            <button @click="setContent">设置内容</button>
            <button @click="insertText">插入文本</button>
            <button @click="insertImage">插入图片</button>
            <button @click="insertSpan">插入span</button>
            <button @click="clear">清空</button>
        </div>
    </div>
</template>

<script>
import inputBox from './input-box.vue'
export default {
    components: {
        inputBox
    },
    data() {
        return {
            input: null
        }
    },
    mounted() {
        this.input = this.$refs.inputBox
    },
    methods: {
        change(val) {
            // console.log(val)
        },
        pasteFileChange(val) {
            console.log(val)
        },
        clear() {
            this.input.clearContent()
        },
        // 模拟设置内容（切换会话设置缓存）
        setContent() {
            const text = '设置内容模拟'
            this.input.setContent(text)
        },
        // 插入文本
        insertText() {
            this.input.insertContent({
                type: 'text',
                content: '插入文本'
            })
        },
        // 插入图片
        insertImage() {
            this.input.insertContent({
                type: 'image',
                imgKey: 'image',
                uuid: '123',
                content: 'https://img0.baidu.com/it/u=3964621115,1474701746&fm=11&fmt=auto&gp=0.jpg'
            })
        },
        // 插入span
        insertSpan() {
            this.input.insertContent({
                type: 'node',
                content: '<span>我的太阳</span>'
            })
        }
    }
}
</script>

<style lang="less">
.container {
    width: 800px;
    height: 400px;
    margin: 200px auto 0;
    padding: 10px;
    box-sizing: border-box;
}
.mock {
    width: 500px;
    margin: 50px auto 0;
    > button {
        cursor: pointer;
        padding: 5px;
        margin-right: 20px;
    }
}
.textarea {
    border: 1px solid #dedede;
}
</style>
